FROM golang:1.10.3-alpine3.8 as builder

ENV GOPATH /go
ENV CODIS  ${GOPATH}/src/github.com/CodisLabs/codis
ENV PATH   ${GOPATH}/bin:${PATH}:${CODIS}/bin
COPY . ${CODIS}

RUN echo -e "https://mirrors.aliyun.com/alpine/v3.8/main/\nhttps://mirrors.aliyun.com/alpine/v3.8/community/" > /etc/apk/repositories ;\
    apk add --no-cache --virtual .build-deps \
        make \
        bash \
        gcc \
        musl-dev \
        autoconf \
        linux-headers \
    ; \
    make -C ${CODIS} distclean ;\
    make -C ${CODIS} build-all ;\
    apk del .build-deps

FROM alpine:3.8
ENV PATH   ${PATH}:/codis/bin

RUN echo -e "https://mirrors.aliyun.com/alpine/v3.8/main/\nhttps://mirrors.aliyun.com/alpine/v3.8/community/" > /etc/apk/repositories ;\
    apk add --no-cache tzdata ;\
    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

COPY --from=builder /go/src/github.com/CodisLabs/codis /codis

RUN cd /codis \
&& mkdir data \
&& chmod 777 data \
&& mkdir log \
&& chmod 777 log

WORKDIR /codis